﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	上传图片
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <% 
    using (Html.BeginForm("UploadImage", "Reporting", FormMethod.Post, new { id = "inputForm", enctype = "multipart/form-data" }))
    {
    %>
    <div style="margin-top:25px">上传图片：<input type="file" id="image" name="image" size="12" /></div>
    <div style="margin-top:15px;text-align:center"><input id="submit" type="submit" value="提  交" /></div>
    <%
    }
    %>

    <script type="text/javascript" src="../../Scripts/ajaxfileupload.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#submit").click(function () {
                var imgPath = document.getElementById("image").value;
                if (imgPath == null || imgPath == "") {
                    alert("请浏览图片");
                    return false;
                };

                $.ajaxFileUpload({
                    async: false,
                    cache: false,
                    type: 'POST',
                    dataType: "text",
                    fileElementId: 'image',    //file的Id
                    url: "/Reporting/UploadImage", //请求的action路径
                    error: function () {//请求失败处理函数 
                        alert('请求失败');
                    },
                    success: function (data) { //请求成功后处理函数。
                        window.returnValue = data; //返回父页面 
                        window.close();
                    }
                });
            });
        });
    </script> 
</asp:Content>
